<template>
  <el-row
    type="flex"
    justify="space-between"
    align="middle"
    style="height: 40px; width: 100%"
  >
    <el-col :span="20">
      <span>{{ nodedata.name }}</span>
    </el-col>
    <el-col :span="4">
      <el-row type="flex">
        <!-- 两个内容 -->
        <el-col :span="12">{{ nodedata.manager }}</el-col>
        <el-col :span="12">
          <!-- 下拉菜单 element -->
          <el-dropdown @command="command">
            <span> 操作<i class="el-icon-arrow-down" /> </span>
            <!-- 下拉菜单 -->
            <el-dropdown-menu slot="dropdown">
              <el-dropdown-item command="add"> 添加子部门 </el-dropdown-item>
              <el-dropdown-item command="edit" v-if="isroot">
                编辑部门</el-dropdown-item
              >
              <el-dropdown-item command="delet" v-if="isroot">
                删除部门
              </el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>
        </el-col>
      </el-row>
    </el-col>
  </el-row>
</template>

<script>
import { deletpartmentapi } from '@/api/departments'
export default {
  props: {
    nodedata: {
      type: Object,
      require: true
    },
    isroot: {
      type: Boolean,
      default: true
    }
  },
  methods: {
    command(command) {
      if (command === 'add') {
        // 点击添加
        this.$emit('opendialogVisible', this.nodedata)
      }
      if (command === 'edit') {
        // 点击编辑
        this.$emit('aditdialogVisible', this.nodedata)
      }
      if (command === 'delet') {
        // 点击删除
        this.$confirm('此操作将永久删除该部门，是否继续', '温馨提示')
          .then(async () => {
            await deletpartmentapi(this.nodedata.id)
            this.$emit('getdepart')
            this.$message.success('删除成功')
          })
          .catch(() => {
            console.log('点击取消')
          })
      }
      console.log(command)
    }
  }
}
</script>

<style scoped lang="scss"></style>
